package com.cn.demo4.servlet.index;

import com.alibaba.fastjson.JSONObject;
import com.cn.demo4.model.*;
import com.cn.demo4.service.*;
import com.cn.demo4.service.impl.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 前台首页控制层
 * @author LXJ
 * DATE 2021-01-05
 */
@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        //公司信息
        ICompanyService iCompanyService = new CompanyServiceImpl();
      CompanyModel companyModel = iCompanyService.getCompanyModelListForHome();
//        req.setAttribute("companyModelList",companyModelList);


        //导航信息
        INavService iNavService = new NavServiceImpl();
        List<NavModel> navModelList = iNavService.getNavModelListForHome();
//        req.setAttribute("navModelList",navModelList);
        //新闻信息
        INewsService iNewsService = new NewsServiceImpl();
        List<NewsModel> newsModelList = iNewsService.getNewsModelListForHome();
//        req.setAttribute("newsModelList",newsModelList);
        //新闻类型
        INewsTypeService iNewsTypeService = new NewsTypeServiceImpl();
        List<NewsTypeModel> newsTypeModelList = iNewsTypeService.getNewsTypeModelListForHome();
        //将数据转发给前台
//        req.setAttribute("newsTypeModelList",newsTypeModelList);

        //咨询信息
        IConsultingService iConsultingService = new ConsultingServiceImpl();
        List<ConsultingModel> consultingModelList = iConsultingService.getConsultingModelListForHome();
//        req.setAttribute("consultingModelList",consultingModelList);

        //楼盘信息
        IProductService iProductService = new ProductServiceImpl();
        List<ProductModel> productModelList = iProductService.getProductModelListForHome();
//        req.setAttribute("productModelList",productModelList);

        //留言信息
        IOnlineService iOnlineService = new OnlineServiceImpl();
        List<OnlineModel> onlineModelList = iOnlineService.getOnlineModelListForHome();
//        req.setAttribute("onlineModelList",onlineModelList);

        //人力资源信息
        IHrService iHrService = new HrServiceImpl();
        List<HrModel> hrModelList = iHrService.getHrModelListForHome();
//        req.setAttribute("hrModelList",hrModelList);
        //页面转发，转发数据
//        req.getRequestDispatcher("/index/jsp/home.jsp").forward(req,resp);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyModel",companyModel);
        jsonObject.put("navModelList",navModelList);
        jsonObject.put("newsModelList",newsModelList);
        jsonObject.put("newsTypeModelList",newsTypeModelList);
        jsonObject.put("consultingModelList",consultingModelList);
        jsonObject.put("productModelList",productModelList);
        jsonObject.put("onlineModelList",onlineModelList);
        jsonObject.put("hrModelList",hrModelList);
        resp.getWriter().println(jsonObject);

    }

}
